package de.rosstauscher.jculfw.tools;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.Socket;

import de.rosstauscher.jculfw.JCulFW;
import de.rosstauscher.jculfw.fs20.FS20CommandCode;

/**********************************************************
 * Application to send FS20 commands to the CUNO
 * @author Rossi java@rosstauscher.de
 *********************************************************/

public class FS20 {

	/**********************************************************
     * Usage: java FS20 cuno housecode device code command  
     * @param args
     * @throws IOException
     *********************************************************/
	
    public static void main( String[] args ) throws IOException
    {
    	if (args.length != 4) {
    		System.out.println("Usage: FS20 host:port housecode command");
    		return;
    	}
        FS20CommandCode command = FS20CommandCode.valueOf(args[3]);
        if (command == null) {
        	System.out.println("Command must be one of: "+FS20CommandCode.values());
        }
    	//TODO do some minimum command line argument format validation?
    	
    	String[] host = args[0].split(":");
        Socket socket = new Socket(host[0], Integer.parseInt(host[1]));
        InputStream in = socket.getInputStream();
        OutputStream out = socket.getOutputStream();
        JCulFW cul = new JCulFW(in, out);
		cul.sendFS20Message(args[1], args[2], command.toHex(), null);
    }
}
